<!-- class {
  constructor(input, init = {}) {
    if (input === kInit) {
      return;
    }
    webidl.argumentLengthCheck(arguments, 1, { header: "Request constructor" });
    input = webidl.converters.RequestInfo(input);
    init = webidl.converters.RequestInit(init);
    this[kRealm] = {
      settingsObject: {
        baseUrl: getGlobalOrigin()
      }
    };
    let request = null;
    let fallbackMode = null;
    const baseUrl = this[kRealm].settingsObject.baseUrl;
    let signal = null;
    if (typeof input === "string") {
      let parsedURL;
      try {
        parsedURL = new URL(input, baseUrl);
      } catch (err) {
        throw new TypeError("Failed to parse URL from " + input, { cause: err });
      }
      if (parsedURL.username || parsedURL.password) {
        throw new TypeError("Request cannot be constructed from a URL that includes credentials: " + input);
      }
      request = makeRequest({ urlList: [parsedURL] });
      fallbackMode = "cors";
    } else {
      assert(input instanceof Request);
      request = input[kState];
      signal = input[kSignal];
    }
    const origin = this[kRealm].settingsObject.origin;
    let window = "client";
    if (request.window?.constructor?.name === "EnvironmentSettingsObject" && sameOrigin(request.window, origin)) {
      window = request.window;
    }
    if (init.window !== void 0 && init.window != null) {
      throw new TypeError(`'window' option '${window}' must be null`);
    }
    if (init.window !== void 0) {
      window = "no-window";
    }
    request = makeRequest({
      method: request.method,
      headersList: request.headersList,
      unsafeRequest: request.unsafeRequest,
      client: this[kRealm].settingsObject,
      window,
      priority: request.priority,
      origin: request.origin,
      referrer: request.referrer,
      referrerPolicy: request.referrerPolicy,
      mode: request.mode,
      credentials: request.credentials,
      cache: request.cache,
      redirect: request.redirect,
      integrity: request.integrity,
      keepalive: request.keepalive,
      reloadNavigation: request.reloadNavigation,
      historyNavigation: request.historyNavigation,
      urlList: [...request.urlList]
    });
    if (Object.keys(init).length > 0) {
      if (request.mode === "navigate") {
        request.mode = "same-origin";
      }
      request.reloadNavigation = false;
      request.historyNavigation = false;
      request.origin = "client";
      request.referrer = "client";
      request.referrerPolicy = "";
      request.url = request.urlList[request.urlList.length - 1];
      request.urlList = [request.url];
    }
    if (init.referrer !== void 0) {
      const referrer = init.referrer;
      if (referrer === "") {
        request.referrer = "no-referrer";
      } else {
        let parsedReferrer;
        try {
          parsedReferrer = new URL(referrer, baseUrl);
        } catch (err) {
          throw new TypeError(`Referrer "${referrer}" is not a valid URL.`, { cause: err });
        }
        request.referrer = parsedReferrer;
      }
    }
    if (init.referrerPolicy !== void 0) {
      request.referrerPolicy = init.referrerPolicy;
    }
    let mode;
    if (init.mode !== void 0) {
      mode = init.mode;
    } else {
      mode = fallbackMode;
    }
    if (mode === "navigate") {
      throw webidl.errors.exception({
        header: "Request constructor",
        message: "invalid request mode navigate."
      });
    }
    if (mode != null) {
      request.mode = mode;
    }
    if (init.credentials !== void 0) {
      request.credentials = init.credentials;
    }
    if (init.cache !== void 0) {
      request.cache = init.cache;
    }
    if (request.cache === "only-if-cached" && request.mode !== "same-origin") {
      throw new TypeError("'only-if-cached' can be set only with 'same-origin' mode");
    }
    if (init.redirect !== void 0) {
      request.redirect = init.redirect;
    }
    if (init.integrity !== void 0 && init.integrity != null) {
      request.integrity = String(init.integrity);
    }
    if (init.keepalive !== void 0) {
      request.keepalive = Boolean(init.keepalive);
    }
    if (init.method !== void 0) {
      let method = init.method;
      if (!isValidHTTPToken(init.method)) {
        throw TypeError(`'${init.method}' is not a valid HTTP method.`);
      }
      if (forbiddenMethods.indexOf(method.toUpperCase()) !== -1) {
        throw TypeError(`'${init.method}' HTTP method is unsupported.`);
      }
      method = normalizeMethod(init.method);
      request.method = method;
    }
    if (init.signal !== void 0) {
      signal = init.signal;
    }
    this[kState] = request;
    const ac = new AbortController();
    this[kSignal] = ac.signal;
    this[kSignal][kRealm] = this[kRealm];
    if (signal != null) {
      if (!signal || typeof signal.aborted !== "boolean" || typeof signal.addEventListener !== "function") {
        throw new TypeError("Failed to construct 'Request': member signal is not of type AbortSignal.");
      }
      if (signal.aborted) {
        ac.abort(signal.reason);
      } else {
        const acRef = new WeakRef(ac);
        const abort = function() {
          acRef.deref()?.abort(this.reason);
        };
        if (getEventListeners(signal, "abort").length >= defaultMaxListeners) {
          setMaxListeners(100, signal);
        }
        signal.addEventListener("abort", abort, { once: true });
        requestFinalizer.register(this, { signal, abort });
      }
    }
    this[kHeaders] = new Headers();
    this[kHeaders][kHeadersList] = request.headersList;
    this[kHeaders][kGuard] = "request";
    this[kHeaders][kRealm] = this[kRealm];
    if (mode === "no-cors") {
      if (!corsSafeListedMethods.includes(request.method)) {
        throw new TypeError(`'${request.method} is unsupported in no-cors mode.`);
      }
      this[kHeaders][kGuard] = "request-no-cors";
    }
    if (Object.keys(init).length !== 0) {
      let headers = new Headers(this[kHeaders]);
      if (init.headers !== void 0) {
        headers = init.headers;
      }
      this[kHeaders][kHeadersList].clear();
      if (headers.constructor.name === "Headers") {
        for (const [key, val] of headers) {
          this[kHeaders].append(key, val);
        }
      } else {
        fillHeaders(this[kHeaders], headers);
      }
    }
    const inputBody = input instanceof Request ? input[kState].body : null;
    if ((init.body !== void 0 && init.body != null || inputBody != null) && (request.method === "GET" || request.method === "HEAD")) {
      throw new TypeError("Request with GET/HEAD method cannot have body.");
    }
    let initBody = null;
    if (init.body !== void 0 && init.body != null) {
      const [extractedBody, contentType] = extractBody(init.body, request.keepalive);
      initBody = extractedBody;
      if (contentType && !this[kHeaders][kHeadersList].contains("content-type")) {
        this[kHeaders].append("content-type", contentType);
      }
    }
    const inputOrInitBody = initBody ?? inputBody;
    if (inputOrInitBody != null && inputOrInitBody.source == null) {
      if (initBody != null && init.duplex == null) {
        throw new TypeError("RequestInit: duplex option is required when sending a body.");
      }
      if (request.mode !== "same-origin" && request.mode !== "cors") {
        throw new TypeError('If request is made from ReadableStream, mode should be "same-origin" or "cors"');
      }
      request.useCORSPreflightFlag = true;
    }
    let finalBody = inputOrInitBody;
    if (initBody == null && inputBody != null) {
      if (util.isDisturbed(inputBody.stream) || inputBody.stream.locked) {
        throw new TypeError("Cannot construct a Request with a Request object that has already been used.");
      }
      if (!TransformStream) {
        TransformStream = require("stream/web").TransformStream;
      }
      const identityTransform = new TransformStream();
      inputBody.stream.pipeThrough(identityTransform);
      finalBody = {
        source: inputBody.source,
        length: inputBody.length,
        stream: identityTransform.readable
      };
    }
    this[kState].body = finalBody;
  }
  get method() {
    webidl.brandCheck(this, Request);
    return this[kState].method;
  }
  get url() {
    webidl.brandCheck(this, Request);
    return URLSerializer(this[kState].url);
  }
  get headers() {
    webidl.brandCheck(this, Request);
    return this[kHeaders];
  }
  get destination() {
    webidl.brandCheck(this, Request);
    return this[kState].destination;
  }
  get referrer() {
    webidl.brandCheck(this, Request);
    if (this[kState].referrer === "no-referrer") {
      return "";
    }
    if (this[kState].referrer === "client") {
      return "about:client";
    }
    return this[kState].referrer.toString();
  }
  get referrerPolicy() {
    webidl.brandCheck(this, Request);
    return this[kState].referrerPolicy;
  }
  get mode() {
    webidl.brandCheck(this, Request);
    return this[kState].mode;
  }
  get credentials() {
    return this[kState].credentials;
  }
  get cache() {
    webidl.brandCheck(this, Request);
    return this[kState].cache;
  }
  get redirect() {
    webidl.brandCheck(this, Request);
    return this[kState].redirect;
  }
  get integrity() {
    webidl.brandCheck(this, Request);
    return this[kState].integrity;
  }
  get keepalive() {
    webidl.brandCheck(this, Request);
    return this[kState].keepalive;
  }
  get isReloadNavigation() {
    webidl.brandCheck(this, Request);
    return this[kState].reloadNavigation;
  }
  get isHistoryNavigation() {
    webidl.brandCheck(this, Request);
    return this[kState].historyNavigation;
  }
  get signal() {
    webidl.brandCheck(this, Request);
    return this[kSignal];
  }
  get body() {
    webidl.brandCheck(this, Request);
    return this[kState].body ? this[kState].body.stream : null;
  }
  get bodyUsed() {
    webidl.brandCheck(this, Request);
    return !!this[kState].body && util.isDisturbed(this[kState].body.stream);
  }
  get duplex() {
    webidl.brandCheck(this, Request);
    return "half";
  }
  clone() {
    webidl.brandCheck(this, Request);
    if (this.bodyUsed || this.body?.locked) {
      throw new TypeError("unusable");
    }
    const clonedRequest = cloneRequest(this[kState]);
    const clonedRequestObject = new Request(kInit);
    clonedRequestObject[kState] = clonedRequest;
    clonedRequestObject[kRealm] = this[kRealm];
    clonedRequestObject[kHeaders] = new Headers();
    clonedRequestObject[kHeaders][kHeadersList] = clonedRequest.headersList;
    clonedRequestObject[kHeaders][kGuard] = this[kHeaders][kGuard];
    clonedRequestObject[kHeaders][kRealm] = this[kHeaders][kRealm];
    const ac = new AbortController();
    if (this.signal.aborted) {
      ac.abort(this.signal.reason);
    } else {
      this.signal.addEventListener("abort", () => {
        ac.abort(this.signal.reason);
      }, { once: true });
    }
    clonedRequestObject[kSignal] = ac.signal;
    return clonedRequestObject;
  }
} -->